設定Google日曆函式
- 函式說明:https://developers.google.com/apps-script/reference/calendar/calendar?hl=zh-tw#createEvent(String,Date,Date,Object)
- 參數
- 進階參數
/*========================================
設定Google日曆函式
========================================*/
function setCalendar(id, title, startTime, endTime, options) {
startTime = new Date(startTime.replace(/-/g, "/"));//轉換日期格式
endTime = endTime ? new Date(endTime.replace(/-/g, "/")) : '';//轉換日期格式
//透過ID取得日曆
let cal = CalendarApp.getCalendarById(id);
let even;
if(endTime){//時間事件
even = cal.createEvent(title, startTime, endTime, { description: options.description, location: options.location });
}else{//沒有結束日期的全天事件
even = cal.createAllDayEvent(title, startTime, { description: options.description, location: options.location });
}
//設定形成顏色(1~11)
even.setColor(options.color);
return even.getId();
}